
//
//  MJExtension.swift
//  OC-Swift
//
//  Created by 陆文宇 on 2017/2/14.
//  Copyright © 2017年 陆文宇. All rights reserved.
//

import UIKit


extension Bundle {
    
    static var refreshBundle: Bundle {
        return Bundle(path: Bundle(for: MJRefreshComponent.self).path(forResource: "MJRefresh", ofType: "bundle")!)!
    }
    static var bundle: Bundle {
        var language: String = Locale.preferredLanguages.first!
        if language.hasPrefix("en") {
            language = "en"
        } else if language.hasPrefix("zh") {
            if language.range(of: "Hans")?.lowerBound != nil {
                language = "zh-Hans"
            } else {
                language = "zh-Hant"
            }
        } else {
            language = "en"
        }
        return Bundle(path: refreshBundle.path(forResource: language, ofType: "lproj")!)!
    }
    static var arrowImage: UIImage {
        return UIImage(contentsOfFile: refreshBundle.path(forResource: "arrow@2x", ofType: "png")!)!.withRenderingMode(.alwaysTemplate)
    }
    
    static func mj_localizedString(for key: String) -> String {
        return mj_localizedString(forKey: key, value: nil)
    }
    
    static func mj_localizedString(forKey key: String, value: String?) -> String {
        var value = value
        value = bundle.localizedString(forKey: key, value: value, table: nil)
        return Bundle.main.localizedString(forKey: key, value: value, table: nil)
    }

}

extension UIScrollView {
    
    var mj_insetT: CGFloat {
        set {
            contentInset.top = newValue
        }
        
        get {
            return contentInset.top
        }
    }
    var mj_insetB: CGFloat {
        set {
            contentInset.bottom = newValue
        }
        
        get {
            return contentInset.bottom
        }
    }
    var mj_insetL: CGFloat {
        set {
            contentInset.left = newValue
        }
        
        get {
            return contentInset.left
        }
    }
    var mj_insetR: CGFloat {
        set {
            contentInset.right = newValue
        }
        
        get {
            return contentInset.right
        }
    }
    var mj_offsetX: CGFloat {
        set {
            contentOffset.x = newValue
        }
        
        get {
            return contentOffset.x
        }
    }
    var mj_offsetY: CGFloat {
        set {
            contentOffset.y = newValue
        }
        
        get {
            return contentOffset.y
        }
    }
    var mj_contentW: CGFloat {
        set {
            contentSize.width = newValue
        }
        
        get {
            return contentSize.width
        }
    }
    var mj_contentH: CGFloat {
        set {
            contentSize.height = newValue
        }
        
        get {
            return contentSize.height
        }
    }
    
}

extension UIView {
    
    var mj_x: CGFloat {
        set {
            frame.origin.x = newValue
        }
        
        get {
            return frame.origin.x
        }
    }
    var mj_y: CGFloat {
        set {
            frame.origin.y = newValue
        }
        
        get {
            return frame.origin.y
        }
    }
    var mj_w: CGFloat {
        set {
            frame.size.width = newValue
        }
        
        get {
            return frame.size.width
        }
    }
    var mj_h: CGFloat {
        set {
            frame.size.height = newValue
        }
        
        get {
            return frame.size.height
        }
    }
    var mj_size: CGSize {
        set {
            frame.size = newValue
        }
        
        get {
            return frame.size
        }
    }
    var mj_origin: CGPoint {
        set {
            frame.origin = newValue
        }
        
        get {
            return frame.origin
        }
    }
    
}
